<?php

if (!defined('IN_XLP')) {
    exit('Access Denied!');
}

/**
 * Description of photoAction
 * 用户上传图片审核
 * @author xlp
 */
class photoAction extends commonAction {

    function __construct() {
        parent::__construct();
        parent::_checkLogin();
        $this->status = array(1 => '恢复', 0 => '<span class="red">屏蔽</span>');
        $this->useStatus = array('微信', '微社区', '二手置换', '家政', '小区时景', '用户反馈');
    }

    function delete() {
        $id = $this->_postid('id');
        if (!$id) {
            showError('参数丢失');
        }
        $rs = M('album')->where(array('id' => $id))->find();
        if (!$rs) {
            showError('内容不存在');
        }
        if (D('album')->delPhoto($rs['id'], $rs['uid'])) {
            $this->JsonReturn('ok', null, 1);
        } else {
            $this->JsonReturn('抱歉，删除失败');
        }
    }

    function deal() {
        $id = $this->_getid('id');
        $do = $this->_get('do');
        if (!$id || !in_array($do, array('ok', 'invalid'))) {
            showError('参数有误');
        }
        $rs = M('album')->where(array('id' => $id))->find();
        if (!$rs) {
            showError('内容不存在');
        }
        $status = 0;
        if ($do == 'ok' && $rs['status'] != 1) {
            $status = 2;
        }
        if ($do == 'invalid' && $rs['status'] != 0) {
            $status = 1;
        }
        if ($status) {
            M('album')->update(array('status' => ($status - 1)), array('id' => $id));
        }
        $this->JsonReturn('ok', null, 1);
    }

    function index() {
        $p = $this->_getid('p', 1);
        $status = $this->_getid('status', 0);
        $source = $this->_getid('source', 0);
        $uid = $this->_getid('uid', 0);
        $size = C('upload', 'thumb_size');
        $where = array();
        if ($status) {
            $where['status'] = $status - 1;
        }
        if ($source) {
            $where['source_id'] = $source - 1;
        }
        if ($uid) {
            $where['uid'] = $uid;
        }
        $rs = M('album')->where($where)->page($p)->order('id DESC')->findAll();
        $total = M('album')->getTotal();
        $this->assign(array('rs' => $rs, 'total' => $total, 'status' => $this->status, 'p' => $p, 'useStatus' => $this->useStatus, 'size' => 0));
        $this->display();
    }

}
